//
//  TMPreferences.m
//  Textmaster
//
//  Created by Anshu Chimala on 1/2/10.
//  Copyright 2010 Home. All rights reserved.
//

#import "TMPreferences.h"
#import "BBAppSessionLoginState.h"
#import <Sparkle/Sparkle.h>

@implementation TMPreferences

+ (BOOL)pasteTextAfterSearching {
	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
	return [defaults boolForKey:@"tm.preferences.pasteTextAfter"];
}

+ (BOOL)filterByDescription {
	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
	return [defaults boolForKey:@"tm.preferences.filterByDescription"];
}

+ (BOOL)checkForUpdates {
	return [[SUUpdater sharedUpdater] automaticallyChecksForUpdates];
}

+ (BOOL)openAtLogin {
	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
	return [defaults boolForKey:@"tm.preferences.openAtLogin"];
}

+ (void)setPasteTextAfterSearching:(BOOL)value {
	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
	[defaults setBool:value forKey:@"tm.preferences.pasteTextAfter"];
	[defaults synchronize];
}

+ (void)setFilterByDescription:(BOOL)value {
	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
	[defaults setBool:value forKey:@"tm.preferences.filterByDescription"];
	[defaults synchronize];
}

+ (void)setCheckForUpdates:(BOOL)value {
//	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//	[defaults setBool:value forKey:@"tm.preferences.checkForUpdates"];
//	[defaults synchronize];
	
	[[SUUpdater sharedUpdater] setAutomaticallyChecksForUpdates:value];
}

+ (void)setOpenAtLogin:(BOOL)value {
	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
	[defaults setBool:value forKey:@"tm.preferences.openAtLogin"];
	[defaults synchronize];
	
	BBAppSessionLoginState *state = [BBAppSessionLoginState sharedController];
	[state setAppSessionLoginListState:value];
}

+ (KeyCombo)shortcutKeyCombo {
	KeyCombo kc;
	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
	kc.code = [defaults integerForKey:@"tm.preferences.keyCombo.code"];
	kc.flags = [defaults integerForKey:@"tm.preferences.keyCombo.flags"];
	return kc;
}

+ (void)setShortcutKeyCombo:(KeyCombo)combo {
	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
	[defaults setInteger:combo.code forKey:@"tm.preferences.keyCombo.code"];
	[defaults setInteger:combo.flags forKey:@"tm.preferences.keyCombo.flags"];
	[defaults synchronize];
}

@end
